tener algo bemoles 7
A flat is a musical sign similar to a lowercase b that stands in front of a note and lowers it half a tone. Over time and in the plural it came to mean testicles. So this verbal locution is a euphemism, like "tener nosrices", from the colloquial "tener cojones", "tener huevos", which are used in various contexts, meaning to be brave or to dare to deny (not having the balls to do something) or simply expressing irritation at a difficult or complicated situation that perhaps could have been avoided.